package com.gitee.jjnnzb.designpatterninspring.business.login.service.impl;

import com.gitee.jjnnzb.designpatterninspring.business.login.entity.bo.MobileLoginParam;
import com.gitee.jjnnzb.designpatterninspring.business.login.entity.bo.ThirdPartyLoginParam;
import com.gitee.jjnnzb.designpatterninspring.business.login.entity.bo.WebLoginParam;
import com.gitee.jjnnzb.designpatterninspring.business.login.entity.vo.TokenRt;
import com.gitee.jjnnzb.designpatterninspring.business.login.handler.LoginStrategy;
import com.gitee.jjnnzb.designpatterninspring.business.login.service.LoginDemoService;
import com.gitee.jjnnzb.designpatterninspring.common.enums.LoginVersionEnum;
import com.gitee.jjnnzb.designpatterninspring.common.manager.TokenManager;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Jjn
 * @since 2023/8/9 15:52
 */
@Service
@RequiredArgsConstructor
public class LoginDemoServiceImpl implements LoginDemoService {
    
    private final LoginStrategy loginStrategy;
    private final TokenManager tokenManager;
    
    @Override
    public TokenRt webLogin(WebLoginParam webLoginParam) {
        Map<String, Object> map = new HashMap<>();
        map.put("version", LoginVersionEnum.WEB_V1.getVersion());
        map.put("params", webLoginParam);
        return loginStrategy.login(map);
    }
    
    @Override
    public TokenRt thirdPartyLogin(ThirdPartyLoginParam thirdPartyLoginParam) {
        Map<String, Object> map = new HashMap<>();
        map.put("version", LoginVersionEnum.THIRD_PARTY_V1.getVersion());
        map.put("params", thirdPartyLoginParam);
        map.put("token", tokenManager.getToken());
        return loginStrategy.login(map);
    }
    
    @Override
    public TokenRt mobileLogin(MobileLoginParam mobileLoginParam) {
        Map<String, Object> map = new HashMap<>();
        map.put("version", LoginVersionEnum.MOBILE_V1.getVersion());
        map.put("params", mobileLoginParam);
        return loginStrategy.login(map);
    }
}
